package panel.viewSpots.navigationNew
{
	import assists.Scale9Grid;
	import assists.SizeManager;
	import assists.TextFieldUtils;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class RadionBtnClouree extends Sprite
	{
		private var _loader:ResourceLoader;
		private var _label:TextField = new TextField();
		private var _clickBit:Scale9Grid;
		private var _overBit:Scale9Grid;
		
		public static const TYPE_CLICK:int = 1;
		public static const TYPE_OVER:int = 2;
		private var _type:int;
		private var _callBack:Function;
		public var btnType:int;
		public function RadionBtnClouree(loader:ResourceLoader)
		{
			_loader = loader;
			init();
		}
		
		private function init():void
		{
			_label.mouseEnabled = false;
			_label.autoSize = "left";
			
			var bitmap:Bitmap = new _loader.uiManager.navigationClickPng()
			_clickBit = new Scale9Grid(bitmap.bitmapData,40,2);
			bitmap = new _loader.uiManager.navigationNormalPng();
			_overBit = new Scale9Grid(bitmap.bitmapData,40,2);
		
			
			this.addChild(_clickBit);
			this.addChild(_overBit);
			this.addChild(_label);
			
		}
		
		public function set Wid(value:int):void
		{
			
		  SizeManager.changeSizeFromWid(_clickBit,value);
		  SizeManager.changeSizeFromWid(_overBit,value);
		  centerLabel();
		}
		
		public function changeState(isClick:Boolean):void
		{
			if(isClick)
			{
				_type = TYPE_CLICK;
				_clickBit.visible = true;
				_overBit.visible = false;
			}else
			{
				_type = TYPE_OVER;
				_clickBit.visible = false;
				_overBit.visible = true;
			}
		}
		
		public function show(callBack:Function,label:String,type:int = 1):void
		{
			_callBack = callBack;
			TextFieldUtils.setHtmlText(_label,label);
			_type = type;
			if(type == TYPE_CLICK)
			{
				_clickBit.visible = true;
				_overBit.visible = false;
			}else
			{
				_clickBit.visible = false;
				_overBit.visible = true;
			}
			
			centerLabel();
		}
		
		private function centerLabel():void
		{
			_label.y = (_clickBit.height - _label.height) * 0.5;
			_label.x = _clickBit.width * 0.2;
		}
		
	}
}